package com.itheima.mapper;

import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper

public interface StudentMapper {
    /**
     * 学员的条件分页查询
     */
    List<Student> page(StudentQueryParam studentQueryParam);

    /**
     * 添加学员
     */
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id,create_time,update_time)" +
            "VALUES(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void save(Student student);

    /**
     * 根据id查询学员
     */
    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    /**
     * 修改学员信息
     */
    void update(Student student);

    /**
     * 批量删除学员
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 统计班级学员信息
     */
    @Select("select c.name clazzName,count(*) num from student s left join clazz c on c.id = s.clazz_id group by clazz_id")
    List<Map<String, Object>> getStudentClazzData();

    /**
     * 统计学员学历
     */
    List<Map<String, Object>> getStudentDegreeData();
}
